class Solution {
public:
    void setZeroes(vector<vector<int>>& matrix) {
        vector<int> vertical, horizontal;
        int n = matrix.size(), m = matrix[0].size();
        for (int i = 0; i < n; ++i) {
            for (int j = 0; j < m; ++j) {
                if (matrix[i][j] == 0) {
                    vertical.push_back(i);
                    horizontal.push_back(j);
                }
            }
        }
        for (int i : vertical)
            for (int j = 0; j < m; ++j)
                matrix[i][j] = 0;


        for (int j : horizontal)
            for (int i = 0; i < n; ++i)
                matrix[i][j] = 0;

    }
};